import 'package:fate_blind_box/theme/theme_color.dart';
import 'package:fate_blind_box/utils/assets.dart';
import 'package:fate_blind_box/utils/common_widget.dart';
import 'package:fate_blind_box/utils/loading.dart';
import 'package:fate_blind_box/utils/provider.dart';
import 'package:flutter/foundation.dart';
import 'package:flutter/gestures.dart';
import 'package:flutter/material.dart';

import '../../network/Api.dart';
import '../../utils/snack_bar.dart';

//个人简介
class MefeedBack extends StatefulWidget {
  MefeedBack({Key? key}) : super(key: key);

  @override
  State<MefeedBack> createState() => _MefeedBackState();
}

class _MefeedBackState extends State<MefeedBack> {
  final TextEditingController _feedbackController = TextEditingController();
  final TextEditingController _telController = TextEditingController();

  @override
  void initState() {
    // TODO: implement initState
    super.initState();
  }

  // 意见反馈
  _getFeedBack() async {
    if (_feedbackController.text.isEmpty) {
      toast('请输入您的宝贵意见');
      return false;
    }

    if (_telController.text.length < 11) {
      toast('请输入您的手机号');
      return false;
    }

    final res = await Api.getInstance()
        .MeFeedBack(_feedbackController.text, _telController.text);
    final data = res['msg'];
    ThemeSnackBar.show(context, data);
    Navigator.of(context).pop();
  }

  @override
  Widget build(BuildContext context) {
    return AppWidget.navTitleBar(
      title: "意见反馈",
      rightActions: [
        Container(
          margin: const EdgeInsets.only(right: 15, top: 10, bottom: 10),
          height: 31,
          child: TextButton(
            style: TextButton.styleFrom(
              backgroundColor: ThemeColor.appColor,
              shape: RoundedRectangleBorder(
                  borderRadius: BorderRadius.circular(5)),
              textStyle: const TextStyle(color: Colors.white),
            ),
            child: const Text(
              '完成',
              style: TextStyle(color: Colors.white),
            ),
            onPressed: () {
              _getFeedBack();
            },
          ),
        )
      ],
      childWidget: Container(
          margin: const EdgeInsets.fromLTRB(15, 5, 15, 0),
          child: Column(
            children: [
              const SizedBox(
                height: 10,
              ),
              Container(
                color: Colors.white,
                height: 200,
                child: TextField(
                  controller: _feedbackController,
                  maxLength: 100,
                  maxLines: 8,
                  minLines: 6,
                  // scrollPadding: const EdgeInsets.only(right: 5),
                  style: TextStyle(
                    fontSize: 16,
                    color: ThemeColor.textColorSecond,
                  ),
                  decoration: const InputDecoration(
                    hintText: "请输入您的宝贵意见",
                    border: InputBorder.none,
                    contentPadding: EdgeInsets.only(left: 10, top: 10),
                    // contentPadding: EdgeInsets.all(20),
                  ),
                ),
              ),
              const SizedBox(
                height: 10,
              ),
              Container(
                alignment: Alignment.center,
                color: Colors.white,
                height: 50,
                child: TextField(
                  controller: _telController,
                  keyboardType: TextInputType.phone,
                  // maxLength: 100,
                  // maxLines: 5,
                  // minLines: 2,
                  // scrollPadding: const EdgeInsets.all(20),
                  style: TextStyle(
                    fontSize: 16,
                    color: ThemeColor.textColorSecond,
                  ),
                  decoration: const InputDecoration(
                    hintText: "请输入您的联系方式",
                    border: InputBorder.none,
                    contentPadding: EdgeInsets.only(left: 10),
                  ),
                ),
              )
            ],
          )),
      bgColor: ThemeColor.sendMsgColor,
    );
  }
}
